package com.locationtracker.plus.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.locationtracker.plus.app.appViewModel
import com.locationtracker.plus.app.network.apiService
import com.locationtracker.plus.app.util.CacheUtil
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.ext.requestNoCheck

class RequestHomeViewModel : BaseViewModel() {

    var uploadLocationResult = MutableLiveData<Long>()

//    var downloadData: MutableLiveData<DownloadResultState> = MutableLiveData()
//
//    fun museumSwitch() {
//        request({ apiService.museumSwitch() }, {
//            appViewModel.switchInfo.value = it
//        }, isShowDialog = false)
//    }

    fun refreshUserInfo() {
        requestNoCheck(
            { apiService.getUserInfo() },
            {
                if (it.isSucces()) {
                    CacheUtil.setUser(it.data)
                    appViewModel.userInfo.value = it.data
                }
            }
        )
    }

    fun uploadLocation(coordinate: String, address: String) {
        request({ apiService.uploadLocation(coordinate, address) }, {
            uploadLocationResult.value = System.currentTimeMillis()
        }, isShowDialog = false)
    }
}